﻿@model EM.OA.Portal.Models.WFApplyModels
@{
    Layout = "~/Views/Shared/_LayoutContent.cshtml";
}
<style type="text/css">
    .left {
        text-align: left;
        width: 80%;
    }

    .right {
        text-align: right;
        width: 20%;
    }
</style>
<div class="easyui-layout" style="height: 500px;">

    <div data-options="region:'west',split:true,title:'操作'" style="width: 100px;">
        <input type="button" value="我的申请" onclick="LoadApply(false)" /><br />
        <input type="button" value="我的审批" onclick="LoadApply(true)"/>
    </div>
    <div data-options="region:'center',title:'申请审批列表',split:true">
        <table id="list" class="easyui-datagrid" toolbar="#toolbar">
        </table>
    </div>

    <div data-options="region:'east',title:'详细信息',split:true" style="width: 450px;">
        <form id="fm" method="post">
        @Html.HiddenFor(m => m.ApplyID)

    <table width="100%">
        <tr>
            <td class="right">
                @Html.LabelFor(m => m.ApplyUserID)：
            </td>
            <td class="left">
                <div id="div_applyUser"></div>
            </td>
        </tr>
        <tr>
            <td class="right">
                @Html.LabelFor(m => m.ApplyDepartmentID)：
            </td>
            <td class="left">
                <div id="div_applyDepartment"></div>
            </td>
        </tr>
        <tr>
            <td class="right">@Html.LabelFor(m => m.ApplyFlowConfigID)：</td>
            <td class="left">
                <div id="div_applyFlowConfig"></div>
            </td>
        </tr>
        <tr>
            <td class="right" valign="top">
                @Html.LabelFor(m => m.ApplyContent)：
            </td>
            <td class="left">
                <div id="div_applyContent"></div>
            </td>
        </tr>
        @*<tr>
            <td class="right">@Html.LabelFor(m=>m.ApprovalUserID)：</td>
            <td class="left">
                @Html.HiddenFor(m=>m.ApprovalUserID)
                
            </td>
        </tr>*@
        <tr>
            <td class="right" valign="top">@Html.LabelFor(m=>m.AprovalRemark)：</td>
            <td class="left">
                @Html.TextAreaFor(m => m.AprovalRemark, new { @style = "width:80%", @rows = "3", @class = "easyui-validatebox" })
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <select class="easyui-combobox" name="ApprovalStatus" id="ApprovalStatus" style="width: 60px;">
                    <option value="2" selected="selected">提交</option>
                    <option value="3">退回</option>
                </select>
                给
                <input class="easyui-combobox" id="com_ApprovalUserID" name="com_ApprovalUserID" 
                    data-options="valueField:'id',textField:'text'" >
                <input type="hidden" id="NextApprovalUserID" name="NextApprovalUserID" />
            </td>
        </tr>
        <tr>
                <td style="text-align: right;">@Html.CheckBoxFor(m => m.IsWebMessage)</td>
                <td>@Html.LabelFor(m => m.IsWebMessage)</td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.CheckBoxFor(m => m.IsSMS)</td>
                <td>@Html.LabelFor(m => m.IsSMS)</td>
            </tr>
            <tr>
                <td style="text-align: right;">@Html.CheckBoxFor(m => m.IsEmail)</td>
                <td>@Html.LabelFor(m => m.IsEmail)</td>
            </tr>
        <tr>
            @*工作流明细信息*@
            <td colspan="2">
                <table id="approvalList" class="easyui-datagrid" width="80%">
                </table>
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="SaveWorkFlow()">保存</a>
                <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>
        </tr>
    </table>
        <input type="hidden" id="NextFlowConfigDetailID" name="NextFlowConfigDetailID" />
        <input type ="hidden" id="NowApprovalID" name="NowApprovalID" />
        </form>
    </div>
    <input type="hidden" value="@ViewBag.UserID" id="hi_UserID" />
</div>

<script type="text/javascript">
    //初始化列表信息
    $(function () {
        LoadApply(false)
    });

    //初始化列表信息
    function LoadApply(isapproval) {
        //初始化列表信息
        var applyUserID = $('#hi_UserID').val();
        var querData = {
            j_userID: applyUserID,
            j_isapproval: isapproval
        };
        init(querData);
    }

    //初始化列表信息
    function init(queryData) {
        $('#list').datagrid({
            //title: '工作流申请',
            idField: 'ApplyID',
            fitColumns: 'true',
            autoRowHeight: true,
            nowrap: true,
            striped: true,
            pagination: true,
            url: '/WFApply/GetList',
            queryParams: queryData,
            columns: [[
                //{ field: 'ck', checkbox: true },
                { field: 'ApplyID', title: 'id', hidden: true },
                { field: 'FlowKindName', title: '流程类型', width: 150 },
                { field: 'ApplyFlowConfigName', title: '流程名称', width: 180 },
                { field: 'ApplyUserName', title: '申请人', width: 150 },
                { field: 'NextApprovalUserName', title: '审批人', width: 150 },
                { field: 'Status', title: '状态', width: 150 },
                { field: 'ApplyUserID', title: '申请人', width: 180, hidden: true },
                { field: 'ApplyDepartmentID', title: '申请部门', width: 180, hidden: true },
                { field: 'ApplyDepartmentName', title: '申请部门', width: 180, hidden: true },
                { field: 'ApplyFlowConfigID', title: '流程ID', width: 180, hidden: true },
                { field: 'ApplyContent', title: '申请内容', width: 180, hidden: true },
                { field: 'ApprovalUserID', title: '审批人', width: 180, hidden: true },
                { field: 'HaveAttachment', title: '是否有附件', width: 180, hidden: true },
                { field: 'IsWebMessage', title: '是否短消息提醒', width: 180, hidden: true },
                { field: 'IsSMS', title: '是否SMS短信提醒', width: 180, hidden: true },
                { field: 'IsEmail', title: '是否邮件提醒', width: 180, hidden: true },
                { field: 'CreateBy', title: '创建人', width: 180, hidden: true },
                { field: 'CreateTime', title: '创建时间', width: 180, hidden: true },
                { field: 'UpdateBy', title: '修改人', width: 180, hidden: true },
                { field: 'UpdateTime', title: '修改时间', width: 180, hidden: true },
                { field: 'NextFlowConfigDetailID', title: '该流程的下一个FlowConfigDetailID', width: 180, hidden: true },
                { field: 'NowApprovalID', title: '该流程当前申请表ID', width: 180, hidden: true }

            ]],
            onClickRow: function (value, row, index) {
                GetWorkFlowInfo(row);
            }
        });
    }

    //根据row获取工作流信息
    function GetWorkFlowInfo(row) {

        var applyID = row.ApplyID;

        LoadApprovalUsers(applyID);

        var div_applyUser = row.ApplyUserName;
        var div_applyDepartment = row.ApplyDepartmentName;
        var div_applyFlowConfig = row.ApplyFlowConfigName;
        var div_applyContent = row.ApplyContent;
        var hi_NextFlowConfigDetailID = row.NextFlowConfigDetailID;
        var hi_NowApprovalID = row.NowApprovalID;
        
        var hi_ApplyID = row.ApplyID;

        $('#div_applyUser').html(div_applyUser);
        $('#div_applyDepartment').html(div_applyDepartment);
        $('#div_applyFlowConfig').html(div_applyFlowConfig);
        $('#div_applyContent').html(div_applyContent);
        $('#NextFlowConfigDetailID').val(hi_NextFlowConfigDetailID);
        $('#NowApprovalID').val(hi_NowApprovalID);
        
        $('#ApplyID').val(hi_ApplyID);

        LoadApprovalList(hi_ApplyID);
       
    }

    //如果为我的审批时加载审批人
    function LoadApprovalUsers(applyID) {
        $('#com_ApprovalUserID').combobox('reload', '/WFFlowConfig/GetApprovalUsersList?applyID=' + applyID);
    }

    function SaveWorkFlow() {
        var hi_NextApprovalUserID = $('#com_ApprovalUserID').combobox('getValue');
        $('#NextApprovalUserID').val(hi_NextApprovalUserID);

        $('#fm').form('submit', {
            url: "/WFApply/Edit",
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                if (result == 'OK') {
                    alert('保存成功！');
                } else {
                    $.messager.show({
                        title: 'Error',
                        msg: result
                    });
                }
            }
        });
    }


    function LoadApprovalList(applyID) {
        $('#approvalList').datagrid({
            title: '工作流审批明细',
            idField: 'ApprovalID',
            fitColumns: 'true',
            autoRowHeight: true,
            nowrap: true,
            striped: true,
            pagination: true,
            url: '/WFApply/GetApprovallist?applyID=' + applyID,
            columns: [[
                { field: 'ApprovalID', title: 'ID', hidden: true },
                { field: 'StepLevel', title: '级别'},
                { field: 'ApprovalUserName', title: '审批人' },
                {
                    field: 'Status', title: '状态',
                    formatter: function (value, row, index) {
                        if (value == 0) {
                            return "未开始";
                        }
                        if (value == 1) {
                            return "审批中";
                        }
                        if (value == 2) {
                            return "通过";
                        }
                        if (value == 3) {
                            return "退回";
                        }
                        if (value == 4) {
                            return "完成";
                        }
                    }
                },
                {
                    field: 'ApprovalDate', title: '审批日期',
                    formatter: function (value, row, index) {
                        return formatDate(value, "yyyy-MM-dd hh:mm:00")
                    }
                }

            ]],
        });
    }

</script>
